package lapsnake.model.stmt;

import java.awt.Component;
import lapsnake.model.data.*;

import lapsnake.model.*;
import lapsnake.py.ast.ASTHelperFactory; 
import lapsnake.ui.JTreeLabel;

import java.beans.PropertyVetoException;

import org.python.antlr.ast.*;

/**Wrapper class with helper functions for Print nodes
 * 
 * The print statement in Python is incongruous:
 * -The values field is optional, but only when newLine is true.
 * -newLine can only be false if the print statement is immediately followed by another print statement.*/
public class LapPrint extends LapStatement {

	public final ChildList<LapExpression> values = new ChildList<>(this, LapExpression.class, true);
	public final OptionalChild<LapExpression> destination = new OptionalChild<>(this, LapExpression.class);
	public VetoableProperty<Boolean> newLine = new VetoableProperty<>(Boolean.class);
	
	public LapPrint(PyAST pyAST, ChildField<? super LapPrint> parent, Print node) throws PropertyVetoException {
		super(pyAST, parent, node);
		
		ASTHelperFactory.makeHelper(pyAST, destination, node.getInternalDest());
		ASTHelperFactory.makeHelpers(pyAST, values, node.getInternalValues());
		newLine.setInternal(node.getInternalNl());
		
		buildTextNodes(node);
	}
	
	@Override
	protected Component getFillerComponent(int childIndex,
		ChildField<?> childField)
	{
		if(childField == values)
			return new JTreeLabel("Print", false);
		else if(childField == destination)
		{
			if(destination.isEmpty())
				return new JTreeLabel("to console", false);
			else
				return new JTreeLabel("to", false);
		}
		return null;
	}
}
